#ifndef XICT_DRIVER_TASK_DRIVER_BASE_H
#define XICT_DRIVER_TASK_DRIVER_BASE_H

#include "xict_driver/utils/utils_common.h"
#include "xict_driver/utils/utils_error.h"
#include <functional>
#include <memory>

namespace xict_driver {
    namespace task {
        class ParserBase;

        /**
         * @brief The base class of a sensor driver 驱动基类
         *
         */
        class DriverBase {
        public:
            /**
             * @brief Construct a new Sensor Driver Base object
             *
             */
            DriverBase();

            /**
             * @brief 处理异常
             *
             */
            virtual bool HandleException(double _timestamp) = 0;

            /**
             * @brief 注册异常回掉函数
             *
             * @param _cb_exception
             */
            void RegisterExceptionCallback(
                const std::function<void(const xict_driver::utils::ErrorInfo&)>&
                    _cb_exception);

            /**
             * @brief 上传异常信息
             *
             * @param _error_info
             */
            void
            UploadException(const xict_driver::utils::ErrorInfo& _error_info);

        protected:
            /// @brief 驱动状态
            xict_driver::utils::DriverState driver_state_;
            /// @brief 数据解析器
            std::shared_ptr<ParserBase> parser_;

            /// @brief 异常回调函数
            std::function<void(const xict_driver::utils::ErrorInfo&)>
                cb_exception_;
        };
    }   // namespace task
}   // namespace xict_driver

#endif